package test.threads.queue.stressed.memory;


import cern.jet.random.engine.DRand;
import cern.jet.random.engine.RandomEngine;
import com.lmax.disruptor.EventFactory;

import static com.google.common.base.Preconditions.*;

/**
 * @author cheremin
 * @since 02.03.12,  17:16
 */
public class LongArrayMessage {
    public final long[] array;

    public LongArrayMessage( final long[] array ) {
        checkArgument( array != null, "array can't be null" );
        this.array = array;
    }

    public LongArrayMessage( final int size ) {
        this( new long[size] );
    }

    public static class Factory implements EventFactory<LongArrayMessage> {
        private final int size;
        private final RandomEngine random = new DRand();

        public Factory( final int size ) {
            checkArgument( size > 0, "size(%s) must be >0 ", size );
            this.size = size;
        }

        @Override
        public LongArrayMessage newInstance() {
            final long[] longs = new long[size];
            for ( int i = 0; i < longs.length; i++ ) {
                longs[i] = random.nextLong();
            }
            return new LongArrayMessage( longs );
        }

        @Override
        public String toString() {
            return "Message.new()";
        }
    }
}
